from panda3d.core import *
from direct.gui.OnscreenText import OnscreenText
from direct.actor.Actor import Actor
import random, sys, os, math
import Gui
from Weapon import Weapon

class Player():
    def __init__(self, name):
        #create gui
        self.name = name
        self.hp = 100
        self.ak47 = Weapon("AK47",1,7,"models/AK47",Vec3(0.04,0.05,+0.11),90,0.1,2,90,30,30,False,False,2,4,True,"sounds/ak47-1.wav",Vec3(0.02,0.02,0.02))
        self.deagle = Weapon("DEAGLE",0,12,"models/DEAGLE",Vec3(0.04,0.1,+0.11),90,0.5,2.5,35,7,7,False,False,1,2,False,"sounds/deagle-1.wav")
        self.knife = Weapon("KNIFE",0,25,"models/KNIFE",Vec3(0.05,0.1,+0.11),-90,0.3,2.5,1,1,1,False,False,1,1,True,"sounds/deagle-1.wav")
        self.gunlist = {"AK47":self.ak47,"DEAGLE":self.deagle,"KNIFE":self.knife}
        #(name,type,model,offset,heading,rate,reload,ammo,clip,mclip,canscope,isscoped,spray,recoil,auto,fsound)
        self.equip = ["AK47","DEAGLE","KNIFE"]#,["","",""],""]
        self.current = 1
        self.lastwep = 0
        self.ownmodel = 0
        self.onLadder = 0
        self.isNocliping = 0
        self.team = 0
        self.dummy=render.attachNewNode("dummyNode")
        self.graphiclist = [0]
        self.lastbullethit = [0]
    def SetModel(self):
        if self.ownmodel != 0:
            self.ownmodel.removeNode()
        self.ownmodel = loader.loadModel(self.gunlist[self.equip[self.current]].model)
        self.ownmodel.setScale(self.gunlist[self.equip[self.current]].scale)
        self.ownmodel.reparentTo(render)
        
    def Update(self,task):
        self.status = 0
        self.dummy.setPos(base.Physics.pController.getPos()+Vec3(0,0,1.7))
        self.dummy.setH(base.CamController.heading)
        self.dummy.setP(base.CamController.pitch)
        self.ownmodel.reparentTo(self.dummy)
        self.ownmodel.setPos(self.gunlist[self.equip[self.current]].offset) # 10 = distance between cam and point
        self.ownmodel.setH(self.gunlist[self.equip[self.current]].heading) #this will rotate it 60 degrees around the point
        self.ownmodel.setP(self.gunlist[self.equip[self.current]].offset.getZ())
        base.camera.reparentTo(self.dummy)
        base.camera.setPos(Vec3(0.00,0.0,+0.15))
        return task.cont